<?php

/**
 * 专辑封面模板管理
 * 
 * @copyright xinwei
 * @since 2012-03-23
 */

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	//关键词
	cgi::get($g_cgival["keyword"], "keyword", "");
	$g_cgival["keyword"] = string::un_script_code($g_cgival["keyword"]);
	$g_cgival["keyword"] = string::un_html($g_cgival["keyword"]);
	
	//模板前台显示状态
	cgi::get($g_cgival["front_status"], "front_status", -1);
	$g_cgival["front_status"] = intval($g_cgival["front_status"]);
	
	//页码
	cgi::get($g_cgival["p"], "p", 1);
	$g_cgival["p"] = intval($g_cgival["p"]);
	
	//长度
	cgi::get($g_cgival["pc"], "pc", 20);
	$g_cgival["pc"] = intval($g_cgival["pc"]);
	
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show;
	
	$db = new db_food_album_cover_template();
	$user_db = new db_food_user();
	
	// 拿到当前站点的site_id
	$site_id = admin::admin_get_user_site_id();
	
	$order = " `order` ";	
	
	// 按条件获取专辑列表
	$data['album_cover_template_list'] = $db->admin_get_food_album_cover_template_list_by_site_id($site_id,$g_cgival["keyword"],$g_cgival["front_status"],$order,$g_cgival["p"],$g_cgival["pc"]);

	$g_show["data"] = $data;
	
	// Pager 
	$g_show["count"] = $db->admin_get_food_album_cover_template_count_by_site_id($site_id,$g_cgival["keyword"],$g_cgival["front_status"]);
	
	$max_page = page_bar::get_page_max($g_show["count"], $g_cgival["pc"], $g_cgival["p"]);
	$page_bar_style = array(
			"curt"		=> $g_cgival["p"],
			"max"		=> $max_page,
			"key"		=> "p",
	);
	
	$g_show["page_bar"] = "<b>{$g_show["count"]}</b> 条记录&nbsp;&nbsp;第{$g_cgival["p"]}页&nbsp;共{$max_page}页&nbsp;" . page_bar::bar3($page_bar_style);
	
	
	//当前参数输出到页面	
	$g_show['args'] = $g_cgival;
}

$g_show["error"] = 0;
$g_show["errmsg"] = '';
try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album_cover_template_list.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	if(isset($_GET['debug']))
		print_r($g_show);
	$smarty = p_get_smarty ();
	$smarty->assign ( 'g_show', $g_show );
	$smarty->display ( "foodv2/album/album_cover_template_list.html" );
}

?>